package com.ym.wcp.framework.listener;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

@Component
public class ApplicationInitListener implements ApplicationContextAware {

    public Env env;

    @Override
    public void setApplicationContext(ApplicationContext context) throws BeansException {
        Environment environment = context.getEnvironment();
        String[] activeProfiles = environment.getActiveProfiles();
        for (String proFile : activeProfiles) {
            if ("dev".equalsIgnoreCase(proFile) || "test".equalsIgnoreCase(proFile)) {
                env = Env.DEV;
            } else if ("pro".equalsIgnoreCase(proFile)) {
                env = Env.PRO;
            }
        }
    }

    public enum Env {
        DEV, PRO
    }
}
